package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Member;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/17 17:29
 * @description：
 */
public interface MemberMapper extends BaseMapper<Member> {
    @Select("select * from t_member where telephone=#{telephone}")
    Member findMemeberByTelephone(String telephone);

    @Select("select count(id) from t_member where date_format(reg_time,'%Y-%m-%d') = #{today}")
        //今日新增的会员
    Integer findMemberCountByDate(String today);

    @Select("select count(id) from t_member")
        //总会员数
    Integer findMemberTotalCount();

    @Select("select count(id) from t_member where date_format(reg_time,'%Y-%m-%d') >= #{thisWeekMonday}")
        //根据日期统计新增会员数，统计指定日期之后的新增会员数
    Integer findMemberCountAfterDate(String thisWeekMonday);

    //性别报表
    @Select("select sex name,count(*) value from t_member\n" +
            "group by sex")
    List<Map> selectMemberSexPercent();

    // 会员数量折线图
    @Select("select date_format(reg_time,'%Y-%m-%d') create_date,count(*) value from t_member\n" +
            "group by create_date\n" +
            "having create_date >=#{startData} and create_date <=#{endData}")
    List<Map> selectMemberNumLineChart(@Param("startData") String startData, @Param("endData") String endData);
}
